package com.fbinggun.fattribute.attribute.other;

import com.fbinggun.fattribute.FAttributePlugin;
import com.fbinggun.fattribute.attribute.AOther;
import com.fbinggun.fattribute.attribute.IAttribute;
import com.fbinggun.fattribute.effect.BleedEffect;
import com.fbinggun.fattribute.effect.IEffect;
import com.fbinggun.fattribute.data.DataManage;
import com.fbinggun.fattribute.data.EntityData;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

import java.util.Map;

public class Bleed extends AOther {
    @Override
    public Map<IAttribute, Double> modifyDamage(EntityData entityData, Map<IAttribute, Double> map, EntityDamageByEntityEvent event) {
        if(event.getEntity() instanceof LivingEntity) {
            EntityData damageEntityData = DataManage.getData((LivingEntity) event.getEntity());
            Map<IEffect,Integer> effects =damageEntityData.getiEffects();
            if(effects!=null&&effects.size()!=0) {
                for (IEffect effect : effects.keySet()) {
                    if (effect instanceof BleedEffect) {
                        effect.setDuration(100);
                        effect.setModification(getValue(entityData));
                        damageEntityData.iEffects.put(effect,100);
                        return map;
                    }
                }
            }
            damageEntityData.addEffect(new BleedEffect(100,getValue(entityData),entityData));
        }
        return map;
    }

    @Override
    public String getKey() {
        return FAttributePlugin.plugin.getConfigKey("Bleed");
    }

    @Override
    public String getID() {
        return "Bleed";
    }

    @Override
    public int getCombat() {
        return 20;
    }
}
